package com.inqbarna.tablefixheaders.samples.slice;

import com.inqbarna.tablefixheaders.TableFixHeaders;
import com.inqbarna.tablefixheaders.samples.ResourceTable;
import com.inqbarna.tablefixheaders.samples.adapters.MatrixTableAdapter;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

public class SimpleTable extends AbilitySlice {

    TableFixHeaders tableFixHeaders;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);

        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(getContext())
            .parse(ResourceTable.Layout_table, null, false);

        tableFixHeaders = (TableFixHeaders) rootLayout.findComponentById(ResourceTable.Id_table);
        MatrixTableAdapter<String> matrixTableAdapter = new MatrixTableAdapter<String>(this, new String[][] {
            {
                "Header 1", "Header 2", "Header 3", "Header 4", "Header 5", "Header 6"
            }, {
            "Lorem", "sed", "do", "eiusmod", "tempor", "incididunt"
        }, {
            "ipsum", "irure", "occaecat", "enim", "laborum", "reprehenderit"
        }, {
            "dolor", "fugiat", "nulla", "reprehenderit", "laborum", "consequat"
        }, {
            "sit", "consequat", "laborum", "fugiat", "eiusmod", "enim"
        }, {
            "amet", "nulla", "Excepteur", "voluptate", "occaecat", "et"
        }, {
            "consectetur", "occaecat", "fugiat", "dolore", "consequat", "eiusmod"
        }, {
            "adipisicing", "fugiat", "Excepteur", "occaecat", "fugiat", "laborum"
        }, {
            "elit", "voluptate", "reprehenderit", "Excepteur", "fugiat", "nulla"
        },
        });
        tableFixHeaders.setAdapter(matrixTableAdapter);
        super.setUIContent(rootLayout);
    }

    @Override
    protected void onBackPressed() {
        super.onBackPressed();
        tableFixHeaders.setAdapter(null);
    }

}
